#include<iostream>
using namespace std;
int a[100001],b[100001],c[100001][3],d[21][2];
int main()
{
    freopen("detect.cpp.in","r",stdin);
    freopen("detect.cpp.out","w",stdout);
    int T,i,n,m,p,l,v,ans=0;
    cin>>T;
    for(p=1;p<=T;p++)
    {
        ans=0;
        cin>>n>>m>>l>>v;
        for(i=1;i<=n;i++) {cin>>c[i][0]>>c[i][1]>>c[i][2];if(c[i][1]>v) ans++;}
        for(i=1;i<=m;i++) cin>>a[i];
        d[p][0]=ans;
        d[p][1]=m-1;
    }
    for(i=1;i<=T;i++) cout<<d[i][0]<<" "<<d[i][1]<<endl;
    return 0;
}
